import java.util.HashSet;

/**
* @description: TODO
* @author hewei
* @date 2022/9/24 15:23
* @version 1.0
*/

public class TransportationHub {

    public int transportationHub(int[][] path) {
        int[] inedeg = new int[1001];
        HashSet<Integer> set = new HashSet<>();
        boolean[] flag = new boolean[1001];
        for (int[] ints : path) {
            inedeg[ints[1]]++;
            flag[ints[0]] = true;
            set.add(ints[1]);
            set.add(ints[0]);
        }
        for (int i = 0; i < 1001; i++) {
            if (inedeg[i] == set.size() && !flag[i]) return i;
        }
        return -1;
    }
}
